#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<algorithm>
using namespace std;

typedef long long LL;
const int N = 2e5 + 10;
LL a[N];
LL n, c;
int main()
{
	cin >> n >> c;
	for (int i = 1; i <= n; i++) cin >> a[i];
	sort(a + 1, a + 1 + n);
	LL ret = 0;
	for (int right = 2; right <= n; right++)
	{
		LL target = a[right] - c;
		auto it1 = lower_bound(a + 1, a + right,target);
		auto it2 = upper_bound(a + 1, a + right,target);
		ret += it2 - it1;
	}
	cout << ret << endl;
	return 0;
}